<?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class Controller extends CController
{
	/**
	 * @var string the default layout for the controller view. Defaults to '//layouts/column1',
	 * meaning using a single column layout. See 'protected/views/layouts/column1.php'.
	 */
	//public $layout='//layouts/column1';
	public $layout = 'main';
	/**
	 * @var array context menu items. This property will be assigned to {@link CMenu::items}.
	 */
	public $menu=array();
	/**
	 * @var array the breadcrumbs of the current page. The value of this property will
	 * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
	 * for more details on how to specify this property.
	 */
	public $breadcrumbs=array();
	
	/**
	 * @var string the message for detail store in logs.Default to empty string
	 */
	public $logMessage = "";
	/**
	 * @var boolean to store log or not.
	 */
        
	public $writeLog = true;

 	/*
	 * The method takes one argument, which will be the action 
	 * The purpose of the method is to log the every actions made by user
	 * @param Action action
	 */
 	protected function afterAction($action)
    {   
        if($this->writeLog)
        {
        	$session=new CHttpSession;
  			$session->open();
  			/**
  			 * hack for twice entry in DB
  			 * TODO need to check better solutions
  			 */
        	/* Temporary block to stop logging
        	if(isset($session['logged'])&&$session['logged']){
        		$session['logged']=false;
        		return;
        	}
    		$this->logMessage .= $_SERVER['QUERY_STRING'];
            $sql = "INSERT INTO {{logs}} VALUES ('".Yii::app()->user->id."','".$_SERVER['REMOTE_ADDR']."','".date("Y-m-d H:i:s")."','".$this->getId()."','".$this->getAction()->getId()."','".$this->logMessage."')";
            $command = Yii::app()->db->createCommand($sql);
            $command->execute();
  			$session['logged']=true;*/
        }
    }
}